package com.ztgf.commodity.service;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ztgf.commodity.common.config.YmlConfig;
import com.ztgf.commodity.mapper.CommoditySalesAttributesRelationMapper;
import com.ztgf.commodity.models.bo.CommoditySalesAttributesRelationSaveBO;
import com.ztgf.commodity.models.dto.CommoditySalesAttributesRelationDTO;
import com.ztgf.commodity.models.service.ICommoditySalesAttributesRelationService;
import com.ztgf.commodity.models.vo.CommoditySalesAttributesRelationVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@DubboService
public class CommoditySalesAttributesRelationServiceImpl extends ServiceImpl<CommoditySalesAttributesRelationMapper, CommoditySalesAttributesRelationDTO>
        implements ICommoditySalesAttributesRelationService {

    @Resource
    private YmlConfig ymlConfig;

    @Override
    public boolean add(CommoditySalesAttributesRelationSaveBO saveBO) {
        CommoditySalesAttributesRelationDTO dto = new CommoditySalesAttributesRelationDTO();
        dto.setCommodityId(saveBO.getCommodityId());
        dto.setSpecificationId(saveBO.getSpecificationId());
        dto.setAttributesIds(saveBO.getAttributesIds());
        dto.setAttributesNames(saveBO.getAttributesNames());
        dto.setId(ymlConfig.getPkId());
        return this.insert(dto);
    }

    @Override
    public List<CommoditySalesAttributesRelationVO> queryGoodsSalesAttributes(Long goodsId) {
        return baseMapper.queryGoodsSalesAttributes(goodsId);
    }
}
